import { request } from "../request";

export const articleApi = {
  //发帖
  addArticle: (data) => {
    return request("/article", "POST", data);
  },
  //更新帖子
  updateArticle: (articleId, data) => {
    return request(`/article/${articleId}`, "PUT", data);
  },
  // 获取最近文章列表
  getRecentArticles: (p = 1, size = 10) => {
    return request("/api/articles/recent", "GET", { p, size });
  },

  // 获取点赞文章列表
  getGoodArticles: (p = 1, size = 10) => {
    return request("/api/articles/recent/good", "GET", { p, size });
  },

  // 获取热门文章列表
  getHotArticles: (p = 1, size = 10) => {
    return request("/api/articles/recent/hot", "GET", { p, size });
  },

  // 获取最近回复文章列表
  getRecentReplyArticles: (p = 1, size = 10) => {
    return request("/api/articles/recent/reply", "GET", { p, size });
  },

  // 获取指定用户的帖子列表
  getUserArticles: (username, p = 1, size = 20) => {
    return request(`/api/user/${username}/articles`, "GET", { p, size });
  },
  //打赏获取隐藏内容
  rewardArticle: (articleId) => {
    return request(`/article/reward?articleId=${articleId}`, "POST");
  },
  // 获取文章详情
  getArticleDetail: (articleId) => {
    return request(`/api/article/${articleId}`);
  },
  //感谢文章 确定赠送 20 积分给该帖作者以表谢意？
  thankArticle: (articleId) => {
    return request(`/article/thank?articleId=${articleId}`, "POST");
  },
  // 置顶帖子
  stickArticle: (articleId) => {
    return request(`/article/stick?articleId=${articleId}`, "POST");
  },
  //获取帖子的评论列表 获取第一页时，data中会有articleNiceComment，即优质回帖。
  getArticleComments: (articleId, p = 1) => {
    return request(`/api/comment/${articleId}`, "GET", { p });
  },
  // 发表评论
  addComment: (articleId, commentContent) => {
    return request("/comment", "POST", { articleId, commentContent });
  },

  // 回复评论
  addReplyComment: (articleId, commentContent, commentOriginalCommentId) => {
    return request("/comment", "POST", {
      articleId,
      commentContent,
      commentOriginalCommentId,
    });
  },
  //删除评论
  deleteComment: (commentId) => {
    return request(`/comment/${commentId}/remove`, "POST");
  },
  //感谢评论
  //注意：不能给自己点感谢！会报错，记得做处理哦。
  //另外，感谢是不能取消的，会扣除15积分送给对方。
  thankComment: (commentId) => {
    return request(`/comment/thank`, "POST", { commentId });
  },
  // 点赞文章
  likeArticle: (dataId) => {
    return request(`/vote/up/article`, "POST", { dataId });
  },

  // 点赞评论
  likeComment: (dataId) => {
    return request(`/vote/up/comment`, "POST", { dataId });
  },
  //获取文章在线人数
  getArticleOnline: (articleId) => {
    return request(`/api/article/heat/${articleId}`, "GET");
  },

  // 标签相关接口
  // 获取标签下的帖子列表
  getTagArticles: (tagURI, p = 1, size = 10) => {
    return request(`/api/articles/tag/${tagURI}`, "GET", { p, size });
  },

  // 按热门程度获取标签下的帖子
  getTagHotArticles: (tagURI, p = 1, size = 10) => {
    return request(`/api/articles/tag/${tagURI}/hot`, "GET", { p, size });
  },

  // 按点赞获取标签下的帖子
  getTagGoodArticles: (tagURI, p = 1, size = 10) => {
    return request(`/api/articles/tag/${tagURI}/good`, "GET", { p, size });
  },

  // 按最近回复获取标签下的帖子
  getTagReplyArticles: (tagURI, p = 1, size = 10) => {
    return request(`/api/articles/tag/${tagURI}/reply`, "GET", { p, size });
  },

  // 按优选获取标签下的帖子
  getTagPerfectArticles: (tagURI, p = 1, size = 10) => {
    return request(`/api/articles/tag/${tagURI}/perfect`, "GET", { p, size });
  },
};
